﻿<extend name="Public:office" />
<block name="title"><title>部门任务卡</title></block>
<block name="header_styles">
    <style type="text/css">
        .main-wrapper .container {
            background-color: #ffffff;
        }
    </style>
</block>
<block name="main">
    <div class="tabs-wrapper">
        <include file='Task:menu' />
        <div class="tab-content">
            <div class="tab-pane active" style="min-height: 600px;">
                <div class="task-cards row">
                    <volist name='cards' id='card'>
                        <div class="col-xs-3">
                            <div class="card">
                                <if condition="($deler eq 1) or (($deler eq 2) and ($card.uid eq $uid))" name='deler' value='1'>
                                    <a id="c_{$card.id}" data-id="{$card.id}" href="javascript:void(0);" class="removeCard button-remove">
                                        <i class="fa fa-close"></i>
                                    </a>
                                </if>
                                <a class="card-name" href="{:U('Task/taskcard2',array('card'=>$card['id']))}">{$card.name}</a>
                                <br />
                                <span>创建者：{$card.nickname}</span>
                            </div>
                        </div>
                    </volist>
                    <eq name='adder' value='1'>
                        <div class="col-xs-3">
                            <a href="javascript:void(0);" class="card add">
                                <i class="fa fa-list-ol"></i><br />
                                创建任务卡
                            </a>
                        </div>
                        <else />
                        <empty name='cards'>
                            <div href="javascript:void(0);" class="card" style="margin-left: 10px;margin-right: 10px;">
                                <span>当前无部门任务卡<br />请等待管理层添加</span>
                            </div>
                        </empty>
                    </eq>
                </div>
            </div>
        </div>
    </div>
</block>
<block name="footer_scripts">
    <script type="text/x-kendo-template" id="tplDeleteConfirm">
        <div style="line-height: 25px;width:400px;">
            <br />
            确定要删除任务卡？
            <br />
            此操作将清除任务卡内所有
            <br />
            信息并不可逆，请谨慎操作
            <label id="lblMessages" class="error text-danger" ></label>
            <div>
                <input type="text" id="confirm_text" class="confirm-input" placeholder="请输入“我要删除”后清除数据" />
            </div>
        </div>
    </script>
    <script type="x-kendo-template" id="tplCardItem">
        <div class="col-xs-3">
            <div class="card">
                <a href="javascript:void(0);" class="removeCard button-remove" id="c_#:cardid#" data-id="#:cardid#"><i class="fa fa-close"></i></a>
                <a class="card-name" href="{:U('Task/taskcard2','','')}-card-#:cardid#">#:cardname#</a>
                <br />
                <span>#:creater#</span>
            </div>
        </div>
    </script>
    <script type="x-kendo-template" id="tplAddCard">
        <div>
            <br />
            请输入任务卡名称？
            <br />
            <br />
            <input type="text" id="cardname" class="form-control" value="" maxlength="10" />
        </div>
    </script>
    <script type="text/javascript">
        require(["jquery", "modules/message", "kendoui/kendo.web.min"], function ($, messageBox) {
            $(".removeCard").click(function () {
                var btn = $(this);
                messageBox.confirm({
                    contentId: "#tplDeleteConfirm",
                    title: "删除任务卡",
                    sureText: "清除数据",
                    sure: function () {
                        var confirmText = $("#confirm_text").val();
                        if (confirmText == "") {
                            return false;
                        }
                        if (confirmText == "我要删除") {
                            messageBox.close();
                            //删除后台数据
                            var url = "{:U('Task/delTaskCard_ajax')}";
                            var card = btn.data('id');
                            $.post(url, { 'id': card }, function (data) {
                                var vdata = eval(data);
                                if (vdata.success == 1) {
                                    //window.location.reload();
                                    return false;
                                } else {
                                    messageBox.alert({ content: vdata.msg });
                                    return false;
                                }
                            }, 'json');
                            btn.closest(".col-xs-3").remove();
                        } else {
                            $("#confirm_text").val("");
                            $("#lblMessages").text("输入错误");
                        }
                        return false;
                    }
                });
            });
            

            $(document).ready(function () {
                $(".task-cards a.add").click(function () {
                    messageBox.alert({
                        title: "添加卡片",
                        contentId: "#tplAddCard",
                        sure: function () {
                            var cardname = $("#cardname").val();
                            var tpl = kendo.template($("#tplCardItem").html());
                            //添加后台数据
                            var url = "{:U('Task/addTaskCard_ajax')}";
                            $.post(url, { 'name': cardname }, function (data) {
                                var vdata = eval(data);
                                if (vdata.success == 1) {
                                    var html = kendo.render(tpl, [{ cardname: cardname, cardid: vdata.cardid, creater:vdata.creater }]);
                                    $(".task-cards a.add").closest(".col-xs-3").before(html);
                                    messageBox.close();
                                } else {
                                    messageBox.alert({ content: vdata.msg });
                                }
                            }, 'json');
                            return false;
                        }
                    });

                });
            });
        });
    </script>
</block>
